package com.example.footballsystem.controller;

import com.example.footballsystem.entity.Field;
import com.example.footballsystem.entity.PlayerCard;
import com.example.footballsystem.service.FieldService;
import com.example.footballsystem.service.PlayerCardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/PlayerCard")
@CrossOrigin(origins = "*")
public class PlayerCardController {
    @Autowired
    PlayerCardService playerCardService;
    //获取全部预定信息
    @GetMapping("/getAllPlayerCard")
    public ResponseEntity<List<PlayerCard>> getAllPlayerCard(){
        //log.info(playerCardService.getAllPlayerCard().toString());
        return ResponseEntity.ok().body(playerCardService.getAllPlayerCard());
    }
    @GetMapping("/searchPlayerCard")
    public ResponseEntity<List<PlayerCard>> searchPlayerCard(String info){
        //log.info("123 "+info);
        return ResponseEntity.ok().body(playerCardService.getPlayerCard(info));
    }
    @PostMapping("/addPlayerCard")
    public ResponseEntity<Boolean> addPlayerCard(@RequestBody PlayerCard playerCard){
        //playerCardService.
        return ResponseEntity.ok().body(playerCardService.addPlayerCard(playerCard));
    }
    @PostMapping("/deletePlayerCard")
    public ResponseEntity<Boolean> deletePlayerCard(@RequestBody List<PlayerCard> playerCards){
        for(int i=0;i<playerCards.size();i++){
            playerCardService.deletePlayerCard(playerCards.get(i).getPlayerAccount());
        }
        return ResponseEntity.ok().body(true);
    }
}
